// get header search element with value
function getHeaderSearchWithValue() {
  var ele = document.getElementById('header-search')
  var value = ele.value
  return {
    ele: ele,
    value: value
  }
}
// clear value of search
function clearSearch() {
  var eleObj = getHeaderSearchWithValue()
  if (eleObj.value === '搜索旅行地/酒店/旅游/景点门票/交通') {
    eleObj.ele.setAttribute('value', '')
  }
}
// check value of search
function checkSearch() {
  var eleObj = getHeaderSearchWithValue()
  if (!eleObj.value) {
    eleObj.ele.setAttribute('value', '搜索旅行地/酒店/旅游/景点门票/交通')
  }
}
// add class name for element
function addClassName(element, classname) {
  element.className = element.className + ' ' + classname
}
// remove class name for element
function removeClassName(element, classname) {
  element.className = element.className.replace(classname, '')
}
// Fade in & out about handle
function handleFade(element, type, speed) {
  if (!element) {
    alert('程序错误, 请检查参数!')
    throw new Error('程序错误, 请检查参数!')
  }
  var ele = document.getElementById(element)
  var type = type || 'fadeIn'
  var speed = speed || 40
  var num = type === 'fadeIn' ? 0 : 10
  var flag = false
  var start = setInterval(function () {
    if (type === 'fadeIn') {
      num++
      flag = num >= 10
    } else {
      num--
      flag = num <= 0
    }
    ele.style.opacity = num / 10
    ele.style.filter = 'Alpha(opacity=' + num * 10 + ')'  // IE6-8
    if (flag) {
      clearInterval(start)
    }
  }, speed)
}
// swipe autoplay
function swipeAutoplay(speed, count) {
  var speed = speed || 3000
  var count = count || 4
  var index = 1
  setInterval(function () {
    handleFade('swipe-item' + index++, 'fadeOut')
    if (index > count) {
      index = 1
    }
    handleFade('swipe-item' + index, 'fadeIn')
  }, speed)
}
